package com.mahjong.server.protocolHandler.player;

import com.mahjong.server.common.Common;
import com.mahjong.server.mina.protocol.DataBuf;
import com.mahjong.server.mina.protocol.MessageProtocol;
import com.mahjong.server.model.Player;

public class PlayerInfoResp extends MessageProtocol {

	private static final byte TAG = Common.Resp;

	private static final short PROTOCOL_NUM = 0x0014;

	private byte resultCode;
	private Player player;

	public PlayerInfoResp() {
		setTag(TAG);
		setProtocolNum(PROTOCOL_NUM);
	}

	public PlayerInfoResp(byte resultCode, Player player) {
		this();
		this.resultCode = resultCode;
		this.player = player;
	}

	@Override
	public void respEncode(DataBuf buf) {
		buf.put(resultCode);
		if (resultCode == Common.SUCCESS) {
			buf.putInt(player.getId());
			buf.putString(player.getNickName());
			buf.put((byte) player.getStatus().getValue());
		}
	}
}
